package com.gxa.shop.servlet.account;

import com.alibaba.fastjson.JSON;
import com.gxa.shop.commons.r.R;
import com.gxa.shop.service.account.AccountService;
import com.gxa.shop.service.account.impl.AccountServiceImpl;
import com.gxa.shop.util.MyFormatUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet(name = "DeleteAccount",value = "/account/delete")
public class DeleteAccount extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        Integer id= MyFormatUtils.toInteger(req.getParameter("userId"));
        AccountService accountService=new AccountServiceImpl();
       int row= accountService.deleteAccount(id);
        R r;
        if (row>0){
            r=R.ok("删除成功");
        }else{
            r=R.error("删除失败");
        }
        String jsonResult= JSON.toJSONString(r);
        PrintWriter writer=resp.getWriter();
        writer.write(jsonResult);
        writer.flush();
        writer.close();
    }
}
